package com.cinema.service;

import com.cinema.entity.movie.Schedule;
import com.cinema.util.DataStore;

import java.util.List;

/**
 * 场次服务类，处理场次相关业务逻辑
 */
public class ScheduleService {
    private final DataStore dataStore = DataStore.getInstance();
    private final List<Schedule> scheduleList = dataStore.getScheduleList();

    /**
     * 查看所有场次
     */
    public void listAllSchedules() {
        if (scheduleList.isEmpty()) {
            System.out.println("❌ 暂无场次数据");
            return;
        }

        System.out.println("\n===== 所有场次 =====");
        for (Schedule schedule : scheduleList) {
            System.out.println(schedule + "\n");
        }
    }

    /**
     * 根据ID查找场次
     */
    public Schedule findScheduleById(String scheduleId) {
        for (Schedule schedule : scheduleList) {
            if (schedule.getScheduleId().equals(scheduleId)) {
                return schedule;
            }
        }
        return null;
    }

    /**
     * 添加场次
     */
    public void addSchedule(Schedule schedule) {
        scheduleList.add(schedule);
        dataStore.updateScheduleList();
    }

    /**
     * 删除场次
     */
    public boolean deleteSchedule(String scheduleId) {
        Schedule schedule = findScheduleById(scheduleId);
        if (schedule != null) {
            scheduleList.remove(schedule);
            dataStore.updateScheduleList();
            return true;
        }
        return false;
    }
}

